using CSharpX.Network;
using System;
using UnityEngine;

namespace UnityX
{
    public class NetworkServer : MonoBehaviour
    {
        public static SelectServer<string> server;
        public int prot = 32147;

        private void Awake()
        {
            server = new SelectServer<string>(prot);
            server.message.Connected += Connected;
            server.message.Disconnect += Disconnect;
            server.message.Error += Error;
        }
        private void Start()
        {
            server.Open();
        }
        private void Update()
        {
            server.Update();
        }
        private void OnDestroy()
        {
            if (server != null)
            {
                server.Close();
                server = null;
            }
        }
        private void Connected(Socket<string> socket)
        {
            Log.Event("客户端连接");
        }
        private void Disconnect(Socket<string> socket)
        {
            Log.Warning("客户端断开");
        }
        private void Error(Socket<string> socket, Exception exception)
        {
            Log.Error(exception);
        }
    }
}
